<template>
  <div class="button" :style="handleStyle()" @click="handleClickBtn">
    <div v-if="type == 'add'" class="iconfont icon">&#xe60d;</div>
    <div v-if="type == 'del'" class="iconfont icon">&#xe650;</div>
    <div v-if="type == 'set'" class="iconfont icon">&#xe607;</div>
    <div v-if="type == 'normal'" class="iconfont normal"></div>
    <div class="text">
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    // 用来区别显示icon
    type: {
      default: "normal",
    },
    // 背景色
    bgc: {},
    // 有没有边框、边框颜色
    border: {
      type: String,
      default: "",
    },
    // 文字颜色
    fontColor: {
      type: String,
      default: "#fff",
    },
  },
  mounted() {},
  methods: {
    handleClickBtn() {
      this.$emit("click");
    },
    handleStyle() {
      let color = this.bgc.split("_");
      let style = "";
      if (color.length == 1) {
        style = `color:${this.fontColor};background: ${color[0]};`;
      } else {
        style = `color:${this.fontColor};background: linear-gradient(to bottom, ${color[0]}, ${color[1]});`;
      }
      if (this.border) {
        style = style + `border:1px solid ${this.border}`;
      }
      return style;
    },
  },
};
</script>

<style lang="less" scoped>
.button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 38px;
  line-height: 38px;
  text-align: center;
  color: #fff;
  border-radius: 5px;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  .icon {
    font-size: 12px;
    margin-right: 5px;
  }
  .text {
    font-size: 14px;
  }
}
</style>